//
// Created by songpingwang on 25-7-18.
//


#include <re2/re2.h>
#include <iostream>
#include "../UDataFrame/UDataBase.h"
#include "../UDataFrame/UDataFrame.h"

using namespace NDFrame;


UDataFrame create_df () {
    UDataFrame df_raw{
			{0, 434, 74, 1038, 113, 604, 39,  0, 0, "江苏省医疗门诊投费票据(电子)", ""},
			{1, 718, 121, 734, 138, 16, 17,  0, 0, "C", ""},
			{2, 95, 193, 185, 213, 90, 20,  0, 0, "票据代码:", ""},
			{3, 197, 193, 282, 211, 85, 18,  0, 0, "32060119", ""},
			{4, 954, 193, 1044, 213, 90, 20,  0, 0, "票据号码:", ""},
			{5, 1056, 193, 1161, 211, 105, 18,  0, 0, "0001084072", ""},
			{6, 97, 221, 331, 240, 234, 19,  0, 0, "交款人统一社会信用代码:", ""},
			{7, 343, 221, 532, 238, 189, 17,  0, 0, "**************4318", ""},
			{8, 953, 221, 1023, 240, 70, 19,  0, 0, "校验码:", ""},
			{9, 1034, 221, 1099, 238, 65, 17,  0, 0, "998217", ""},
			{10, 97, 246, 166, 266, 69, 20,  0, 0, "交款人:", ""},
			{11, 177, 244, 240, 266, 63, 22,  0, 0, "吴睿桐", ""},
			{12, 954, 246, 1044, 266, 90, 20,  0, 0, "开票日期:", ""},
			{13, 1056, 246, 1161, 264, 105, 18,  0, 0, "2019-09-09", ""},
			{14, 113, 281, 197, 301, 84, 20,  0, 0, "项目编码", ""},
			{15, 364, 281, 448, 299, 84, 18,  0, 0, "项目名称", ""},
			{16, 637, 281, 678, 301, 41, 20,  0, 0, "单位", ""},
			{17, 756, 281, 797, 301, 41, 20,  0, 0, "数量", ""},
			{18, 873, 281, 916, 301, 43, 20,  0, 0, "标准", ""},
			{19, 1013, 281, 1054, 301, 41, 20,  0, 0, "金额", ""},
			{20, 1067, 281, 1104, 301, 37, 20,  0, 0, "(元)", ""},
			{21, 1266, 281, 1307, 301, 41, 20,  0, 0, "备注", ""},
			{22, 97, 307, 201, 322, 104, 15,  0, 0, "AE04000010", ""},
			{23, 218, 305, 434, 324, 216, 19,  0, 0, "(J)布洛芬混悬液(美林)", ""},
			{24, 600, 305, 701, 324, 101, 19,  0, 0, "100ml:2g*1", ""},
			{25, 804, 307, 836, 322, 32, 15,  0, 0, "1.0", ""},
			{26, 902, 307, 951, 322, 49, 15,  0, 0, "12.91", ""},
			{27, 1124, 307, 1173, 322, 49, 15,  0, 0, "12.91", ""},
			{28, 1270, 307, 1303, 324, 33, 17,  0, 0, "0.0", ""},
			{29, 598, 328, 651, 348, 53, 20,  0, 0, "瓶/瓶", ""},
			{30, 97, 352, 201, 369, 104, 17,  0, 0, "AZ01010201", ""},
			{31, 218, 350, 536, 371, 318, 21,  0, 0, "(J)0.9%氯化钠注射液(百特)[软袋]", ""},
			{32, 598, 350, 701, 371, 103, 21,  0, 0, "250ml*1袋/", ""},
			{33, 804, 352, 836, 369, 32, 17,  0, 0, "1.0", ""},
			{34, 912, 352, 953, 369, 41, 17,  0, 0, "5.65", ""},
			{35, 1132, 352, 1175, 369, 43, 17,  0, 0, "5.65", ""},
			{36, 1270, 352, 1303, 369, 33, 17,  0, 0, "0.0", ""},
			{37, 598, 373, 619, 395, 21, 22,  0, 0, "袋", ""},
			{38, 97, 398, 201, 414, 104, 16,  0, 0, "AE02030006", ""},
			{39, 218, 396, 506, 416, 288, 20,  0, 0, "(J)注射用头孢呋辛钠(明可欣)", ""},
			{40, 598, 396, 703, 416, 105, 20,  0, 0, "0.75g*1瓶/", ""},
			{41, 803, 398, 836, 416, 33, 18,  0, 0, "3.0", ""},
			{42, 912, 398, 953, 414, 41, 16,  0, 0, "20.9", ""},
			{43, 1122, 398, 1175, 414, 53, 16,  0, 0, "62.70", ""},
			{44, 1270, 398, 1303, 414, 33, 16,  0, 0, "0.0", ""},
			{45, 598, 420, 619, 439, 21, 19,  0, 0, "瓶", ""},
			{46, 97, 443, 201, 461, 104, 18,  0, 0, "AX02030728", ""},
			{47, 216, 441, 475, 463, 259, 22,  0, 0, "※(L)帕拉米韦氯化钠注射液", ""},
			{48, 598, 443, 709, 463, 111, 20,  0, 0, "0.15g:0.9g:", ""},
			{49, 803, 443, 836, 461, 33, 18,  0, 0, "2.0", ""},
			{50, 921, 443, 954, 461, 33, 18,  0, 0, "138", ""},
			{51, 1110, 443, 1175, 461, 65, 18,  0, 0, "276.00", ""},
			{52, 1270, 443, 1303, 461, 33, 18,  0, 0, "0.5", ""},
			{53, 600, 467, 701, 486, 101, 19,  0, 0, "100ml*1瓶/", ""},
			{54, 97, 490, 201, 508, 104, 18,  0, 0, "AX020C0340", ""},
			{55, 218, 488, 495, 508, 277, 20,  0, 0, "(J)0.9%氯化钠注射液[塑料瓶]", ""},
			{56, 600, 490, 692, 508, 92, 18,  0, 0, "10ml:0.09", ""},
			{57, 804, 490, 836, 508, 32, 18,  0, 0, "1.0", ""},
			{58, 912, 490, 954, 508, 42, 18,  0, 0, "1.12", ""},
			{59, 1132, 490, 1175, 508, 43, 18,  0, 0, "1.12", ""},
			{60, 1270, 490, 1303, 508, 33, 18,  0, 0, "0.0", ""},
			{61, 598, 512, 682, 531, 84, 19,  0, 0, "g*1支/支", ""},
			{62, 97, 535, 201, 553, 104, 18,  0, 0, "AE02030103", ""},
			{63, 218, 533, 392, 555, 174, 22,  0, 0, "(J)注射用青霉素钠", ""},
			{64, 598, 535, 701, 555, 103, 20,  0, 0, "80万u*1瓶/", ""},
			{65, 803, 537, 836, 553, 33, 16,  0, 0, "1.0", ""},
			{66, 921, 535, 954, 553, 33, 18,  0, 0, "0.4", ""},
			{67, 1132, 535, 1175, 553, 43, 18,  0, 0, "0.40", ""},
			{68, 1270, 535, 1303, 553, 33, 18,  0, 0, "0.0", ""},
			{69, 598, 557, 619, 576, 21, 19,  0, 0, "瓶", ""},
			{70, 95, 580, 181, 598, 86, 18,  0, 0, "Q130100X", ""},
			{71, 216, 578, 298, 600, 82, 22,  0, 0, "肌肉注射", ""},
			{72, 803, 580, 836, 600, 33, 20,  0, 0, "1.0", ""},
			{73, 941, 580, 954, 600, 13, 20,  0, 0, "4", ""},
			{74, 1132, 580, 1175, 598, 43, 18,  0, 0, "4.00", ""},
			{75, 1270, 580, 1303, 600, 33, 20,  0, 0, "0.0", ""},
			{76, 97, 619, 251, 639, 154, 20,  0, 0, "金额合计(大写)", ""},
			{77, 884, 619, 956, 639, 72, 20,  0, 0, "(小写)￥", ""},
			{78, 238, 684, 355, 705, 117, 21,  0, 0, "业务流水号：", ""},
			{79, 360, 686, 456, 703, 96, 17,  0, 0, "212008607", ""},
			{80, 631, 684, 764, 705, 133, 21,  0, 0, "医疗机构类型:", ""},
			{81, 1025, 684, 1116, 703, 91, 19,  0, 0, "医保类型:", ""},
			{82, 236, 707, 286, 727, 50, 20,  0, 0, "性别：", ""},
			{83, 631, 707, 723, 729, 92, 22,  0, 0, "就诊卡号：", ""},
			{84, 1025, 707, 1157, 729, 132, 22,  0, 0, "社会保障号码：", ""},
			{85, 238, 730, 452, 750, 214, 20,  0, 0, "基本医疗保险基金支付:", ""},
			{86, 238, 752, 473, 773, 235, 21,  0, 0, "医保政策范围内个人自付:", ""},
			{87, 631, 752, 867, 773, 236, 21,  0, 0, "医保政策范围外个人自费:", ""},
			{88, 238, 775, 411, 795, 173, 20,  0, 0, "医保个人账户支付:", ""},
			{89, 631, 775, 764, 795, 133, 20,  0, 0, "个人支付金额:", ""},
			{90, 1025, 775, 1118, 795, 93, 20,  0, 0, "支付方式:", ""},
			{91, 156, 797, 202, 843, 46, 46,  0, 0, "南京", ""},
			{92, 218, 799, 234, 818, 16, 19,  0, 0, "记", ""},
			{93, 319, 799, 411, 818, 92, 19,  0, 0, "账户余额:", ""},
			{94, 95, 885, 152, 906, 57, 21,  0, 0, "收款单", ""},
			{95, 645, 885, 713, 904, 68, 19,  0, 0, "复核人:", ""},
			{96, 919, 885, 990, 904, 71, 19,  0, 0, "收款人:", ""},
			{97, 999, 885, 1064, 902, 65, 17,  0, 0, "816101", ""},
			{98, 729, 908, 764, 926, 35, 18,  0, 0, "2-1", ""}
		};
	return df_raw;
}

class MR {
public:
	static const RE2 code_0;
};

const RE2 MR::code_0(R"(票据代码:_(\d+)_票据号码:_(\d+)_交款人统一社会信用代码:_([0-9*]+)_校验码:_(\d+)_交款人:_([\x{4e00}-\x{9fa5}]+)_开票日期:_(\d{4}-\d{1,2}-\d{1,2})_项目编码)");


void test_re_findall (const std::string &all_text) {
	std::string bill_code, bill_no, bill_uusc, check_code, payee, bill_date;
	if (RE2::PartialMatch(all_text, MR::code_0, &bill_code, &bill_no, &bill_uusc, &check_code, &payee, &bill_date)) {
		std::cout << "\n票据代码: " << bill_code
		<< "\n票据号码: " << bill_no
		<< "\n交款人统一社会信用代码: " << bill_uusc
		<< "\n校验码: " << check_code
		<< "\n交款人: " << payee
		<< "\n开票日期: " << bill_date << std::endl;
	} else {
		std::cout << "Match failed!" << std::endl;
	}
}



int main() {
	UDataFrame df_raw = create_df();
	df_raw.print();

	const std::string all_text = df_raw.join_and_replace<Field::TEXT>(' ', "#", "_");
	std::cout << all_text << std::endl;
	test_re_findall(all_text);

	const UDataFrame df_merge = df_raw.DF_merge_line(30,8,"_");
	df_merge.print();

    return 0;
}